<template>
    <el-row>
      <el-col :span="8">
        <el-select :disabled="type=='edit'?true:false" size="small" @change="changeType" v-model="typeCase" placeholder="请选择">
          <el-option v-for="(item,index) in laiyuanData" :key="index" :label="item.desc" :value="item.name"></el-option>
        </el-select>
      </el-col>
      <el-col :span="16">
        <el-select
          v-if="typeCase == ''"
          :disabled="type=='edit'?true:false"
          style="width:100%"
          v-model="phoneTyPe"
          size="small"
          placeholder="请选择"
        >
        </el-select>
        <a-tree-select
          v-if="typeCase == 'COLLEAGUE'"
          showSearch
          allowClear
          style="width: 100%"
          :disabled="type=='edit'?true:false"
          :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
          :treeData="gData"
          treeNodeFilterProp="title"
          placeholder="请选择"
          treeDefaultExpandAll
          @change="onChange"
          :value="phoneTyPe">
        </a-tree-select>
        <el-select
          v-if="typeCase == 'CUSTOMER'"
          :disabled="type=='edit'?true:false"
          style="width:100%"
          size="small"
          filterable
          v-model="phoneTyPe"
          placeholder="请选择"
        >
          <el-option v-for="(item,index) in kehuData" :key="index" :label="item.customerName" :value="item.id"></el-option>
        </el-select>
        <el-select
          v-if="typeCase == 'CHANNEL'"
          :disabled="type=='edit'?true:false"
          style="width:100%"
          size="small"
          v-model="phoneTyPe"
          placeholder="请选择"
        >
          <el-option v-for="(item,index) in qudaoData" :key="index" :label="item.channelName" :value="item.channelId"></el-option>
        </el-select>
      </el-col>
    </el-row>
</template>

<script>
export default {
    props: ['typeid','id','type'],
    data() {
        return {
          typeCase: '',
          phoneTyPe: '',
          laiyuanData: [],
          kehuData: [],
          qudaoData: [],
          gData: []
        };
    },
    created() {

    },
    mounted() {
      this.getKehu()
      this.getQudao()
      this.getTree()
      this.$utils.getEnumberation('postOpportunitySourceType','laiyuanData',this) //来源类型
    },
    methods: {
      getTree() { //获取组织架构树
        this.$post(this.$api.postProviderOrganizationOrganizationUserTree).then(response => {
          if (response.data.succeed) {
            this.gData = []
            if (response.data.data.length > 0) {
              response.data.data.forEach(el=>{
                this.getData(el)
                if (el.title) {
                  this.gData.push(el)
                }
              })
            }
          }
        })
      },
      getData(data) { //处理树数据
        data.title = data.label
        data.value = data.id
        data.key = data.id //
        data.disabled = data.type
        data.scopedSlots = { title: 'title', key: 'key', parentId: 'parentId' }
        if (data.children && data.children.length > 0) {
          for(var i = 0; i < data.children.length; i++) {
            this.getData(data.children[i])
          }
        }
      },
      onChange (value,label, extra) {
        this.phoneTyPe = value
      },
      changeType(value) {
        this.phoneTyPe = ''
      },
      getKehu() { //获取客户下拉数据
        this.$post(this.$api.postCustomerCoreListForContract).then(response => {
          if (response.status == 200) {
              this.kehuData = response.data.data
          }
        })
      },
      getQudao() { //获取渠道下拉数据
        this.$post(this.$api.postChannelListEnabled).then(response => {
          if (response.status == 200) {
              this.qudaoData = response.data.data
          }
        })
      },
    },
    computed: {

    },
    watch: {
      typeCase (value) { //所选择的类型监听
        this.$emit('checkValue',value)
      },
      phoneTyPe (value) { //所选择的值的监听
        this.$emit('input',value)
      },
      typeid (value) { //所选择的值的监听
        this.typeCase = this.typeid
        console.log(this.typeCase)
      },
      id (value) { //所选择的值的监听
        this.phoneTyPe = this.id
        console.log(this.phoneTyPe)
        
      }
    }
};
</script>

<style scoped>

</style>
